package com.simon.app.october.modules.sys.service.impl;

import com.simon.app.october.common.utils.PageUtil;
import com.simon.app.october.common.utils.QueryPage;
import com.simon.app.october.modules.sys.dao.SysLogDao;
import com.simon.app.october.modules.sys.entity.SysLogEntity;
import com.simon.app.october.modules.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao logDao;

    @Override
    public PageUtil getPageByParams(Map<String, Object> params) {
        params = new QueryPage(params);

        int page  = (int) params.get("page");
        int limit = (int) params.get("limit");
        int total = logDao.getTotalByParams(params);
        List<SysLogEntity> list = logDao.getPageByParams(params);
        int pageNum = (int) Math.ceil(total/(double)limit);

        PageUtil<SysLogEntity> pageUtil = new PageUtil<>();
        pageUtil.setList(list);
        pageUtil.setPageSize(limit);
        pageUtil.setCurrPage(page);
        pageUtil.setTotalPage(pageNum);
        pageUtil.setTotalCount(total);
        return pageUtil;
    }
}
